import { getStore, removeStore, setStore } from '@/util/store'

const common = {
  namespaced: true,
  state: {
    useVerifyCode: false, // 是否开启验证码校验 需要在终端也关闭验证码验证
    isLock: getStore('isLock') || false,
    theme: getStore('theme') || '#409EFF',
    lockPasswd: getStore('lockPasswd') || '',
    lockPath: getStore('lockPath') || '/'
  },
  mutations: {
    setLock: (state, { lockPath }) => {
      state.isLock = true
      state.lockPath = lockPath
      setStore('isLock', state.isLock, { type: 'session' })
      setStore('lockPath', state.lockPath, { type: 'session' })
    },
    setLockPasswd: (state, { lockPasswd }) => {
      state.lockPasswd = lockPasswd
      setStore('lockPasswd', state.lockPasswd, { type: 'session' })
    },
    clearLock: state => {
      state.isLock = false
      state.lockPasswd = ''
      removeStore('lockPasswd', 'session')
      removeStore('isLock', 'session')
      removeStore('lockPath', 'session')
    }
  }
}

export default common
